class TujianItem extends eui.ItemRenderer {
	public img_select:eui.Image;
	private img_icon:eui.Image;
	private img_mask:eui.Image;
	private isInit = false;
	private oldData:any;
	public constructor() {
		super();
		this.init();
	}

	protected init()
	{
		this.cacheAsBitmap = true;
		this.skinName = "TujianItemSkin";
		this.addEvent();
	}

	protected addEvent()
	{
		this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.destory, this);
		this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.selectHandle, this);
	}

	protected selectHandle()
	{		
		if(this.data && !this.data["isLocked"])
			GameUtil.dispatchEvent(EventConst.TUJIAN_SELECT, this);
		else
			MessageUtil.tips("还未解锁哦");
	}
	
	protected dataChanged(){
		if(this.oldData == this.data) return;
		this.oldData = this.data;
		this.img_icon.source = this.data["tujianicon"];

		if(this.data['isLocked'])
			this.addMask();
		let logic:TujianUI = UIManager.instance().getLogicByName(UIConst.TUJIAN_UI) as TujianUI;
		//首次
		if(logic)
		{
			if(this.data.id == 1 )
			{
				this.selectHandle();
			}
		}
	}

	protected removeEvent()
	{
		this.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.selectHandle, this);
		this.removeEventListener(egret.Event.REMOVED_FROM_STAGE, this.destory, this);
	}

	public destory()
	{
		this.removeEvent();
	}

	//增加遮罩
	public addMask()
	{
		this.img_mask.visible = true;
		this.img_mask.mask = this.img_icon;
	}
}

window['TujianItem'] = TujianItem;